// pages/movie-more/movie-more.js
Page({
  data: {
    comingsoonList: [],
    showLoading: false
  },
      // 获取即将上映的数据
  getcomingsoonList () {
    const This = this
    const start = this.data.comingsoonList.length
    wx.request({
      url: 'http://api.douban.com/v2/movie/coming_soon?apikey=0df993c66c0c636e29ecbb5344252a4a',
      data:{
        start: start,
        count: 9
      },
      header:{
        "Content-Type":"json"
      },
      success (data) {
        var tempList = This.data.comingsoonList;
        for (var i = 0;i<data.data.subjects.length;i++){
          tempList.push(data.data.subjects[i])
        }
        console.log(data)
        This.setData({
          comingsoonList: tempList,
          showLoading: false
        })
        console.log(This.data.comingsoonList)
      },
      fail (data) {
        // 请求失败，弹出框提示
        wx.showToast({
          title: '网络请求失败',
          icon: 'none'
        })
      }
    })
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    console.log(this.data.showLoading)
    this.getcomingsoonList()
  },
  // 监听用户上拉触底事件
  onReachBottom (e) {
    this.setData({
      showLoading: true
    })
    this.getcomingsoonList()
  },
      // 触碰事件显示跳转movie-detail页面
    onOpendetail (e) {
      const movieId = e.currentTarget.dataset.movieid
      wx.navigateTo({
        url: '../movie-detail/movie-detail?movieId=' + movieId,
      })
    }
})